import java.io.InputStream;
import java.io.OutputStream;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;

import data.BooleanArrayContainer;
import data.BooleanContainer;
import data.ByteArrayContainer;
import data.ByteContainer;
import data.CharArrayContainer;
import data.CharContainer;
import data.CompoundArrayContainer;
import data.CompoundContainer;
import data.DoubleArrayContainer;
import data.DoubleContainer;
import data.FloatArrayContainer;
import data.FloatContainer;
import data.IntArrayContainer;
import data.IntContainer;
import data.LongArrayContainer;
import data.LongContainer;
import data.ShortArrayContainer;
import data.ShortContainer;
import data.StringArrayContainer;
import data.StringContainer;


public class JAXBTest extends SerializationTest {
	private Marshaller marshaller;
	private Unmarshaller unmarshaller;
	
	public JAXBTest(TestRecorder recorder, Storage storage) throws JAXBException {
		super(recorder, storage);
		super.technique = "JAXB";
		JAXBContext context = JAXBContext.newInstance(BooleanContainer.class, BooleanArrayContainer.class,
					ByteContainer.class, ByteArrayContainer.class,
					CharContainer.class, CharArrayContainer.class,
					DoubleContainer.class, DoubleArrayContainer.class,
					FloatContainer.class, FloatArrayContainer.class,
					IntContainer.class, IntArrayContainer.class,
					LongContainer.class, LongArrayContainer.class,
					ShortContainer.class, ShortArrayContainer.class,
					StringContainer.class, StringArrayContainer.class,
					CompoundContainer.class, CompoundArrayContainer.class);
		marshaller = context.createMarshaller();
		unmarshaller = context.createUnmarshaller();
	}

	@Override
	protected void testBoolWrite(boolean value, OutputStream out) throws Exception {
		BooleanContainer container = new BooleanContainer();
		container.value = value;
		marshaller.marshal(container, out);
	}

	@Override
	protected void testBoolWrite(boolean[] value, OutputStream out) throws Exception {
		BooleanArrayContainer container = new BooleanArrayContainer();
		container.values = value;
		marshaller.marshal(container, out);
	}

	@Override
	protected boolean testBoolRead(InputStream in) throws Exception {
		BooleanContainer container = (BooleanContainer) unmarshaller.unmarshal(in);
		return container.value;
	}

	@Override
	protected boolean[] testBoolsRead(InputStream in) throws Exception {
		BooleanArrayContainer container =  (BooleanArrayContainer) unmarshaller.unmarshal(in);
		return container.values;
	}

	@Override
	protected void testByteWrite(byte value, OutputStream out) throws Exception {
		ByteContainer container = new ByteContainer();
		container.value = value;
		marshaller.marshal(container, out);
	}

	@Override
	protected void testByteWrite(byte[] value, OutputStream out) throws Exception {
		ByteArrayContainer container = new ByteArrayContainer();
		container.values = value;
		marshaller.marshal(container, out);
	}

	@Override
	protected byte testByteRead(InputStream in) throws Exception {
		ByteContainer container =  (ByteContainer) unmarshaller.unmarshal(in);
		return container.value;
	}

	@Override
	protected byte[] testBytesRead(InputStream in) throws Exception {
		ByteArrayContainer container =  (ByteArrayContainer) unmarshaller.unmarshal(in);
		return container.values;
	}

	@Override
	protected void testShortWrite(short value, OutputStream out) throws Exception {
		ShortContainer container = new ShortContainer();
		container.value = value;
		marshaller.marshal(container, out);
	}

	@Override
	protected void testShortWrite(short[] value, OutputStream out) throws Exception {
		ShortArrayContainer container = new ShortArrayContainer();
		container.values = value;
		marshaller.marshal(container, out);
	}

	@Override
	protected short testShortRead(InputStream in) throws Exception {
		ShortContainer container =  (ShortContainer) unmarshaller.unmarshal(in);
		return container.value;
	}

	@Override
	protected short[] testShortsRead(InputStream in) throws Exception {
		ShortArrayContainer container =  (ShortArrayContainer) unmarshaller.unmarshal(in);
		return container.values;
	}

	@Override
	protected void testIntWrite(int value, OutputStream out) throws Exception {
		IntContainer container = new IntContainer();
		container.value = value;
		marshaller.marshal(container, out);
	}

	@Override
	protected void testIntWrite(int[] value, OutputStream out) throws Exception {
		IntArrayContainer container = new IntArrayContainer();
		container.values = value;
		marshaller.marshal(container, out);
	}

	@Override
	protected int testIntRead(InputStream in) throws Exception {
		IntContainer container =  (IntContainer) unmarshaller.unmarshal(in);
		return container.value;
	}

	@Override
	protected int[] testIntsRead(InputStream in) throws Exception {
		IntArrayContainer container =  (IntArrayContainer) unmarshaller.unmarshal(in);
		return container.values;
	}

	@Override
	protected void testLongWrite(long value, OutputStream out) throws Exception {
		LongContainer container = new LongContainer();
		container.value = value;
		marshaller.marshal(container, out);
	}

	@Override
	protected void testLongWrite(long[] value, OutputStream out) throws Exception {
		LongArrayContainer container = new LongArrayContainer();
		container.values = value;
		marshaller.marshal(container, out);
	}

	@Override
	protected long testLongRead(InputStream in) throws Exception {
		LongContainer container =  (LongContainer) unmarshaller.unmarshal(in);
		return container.value;
	}

	@Override
	protected long[] testLongsRead(InputStream in) throws Exception {
		LongArrayContainer container =  (LongArrayContainer) unmarshaller.unmarshal(in);
		return container.values;
	}

	@Override
	protected void testFloatWrite(float value, OutputStream out) throws Exception {
		FloatContainer container = new FloatContainer();
		container.value = value;
		marshaller.marshal(container, out);
	}

	@Override
	protected void testFloatWrite(float[] value, OutputStream out) throws Exception {
		FloatArrayContainer container = new FloatArrayContainer();
		container.values = value;
		marshaller.marshal(container, out);
	}

	@Override
	protected float testFloatRead(InputStream in) throws Exception {
		FloatContainer container =  (FloatContainer) unmarshaller.unmarshal(in);
		return container.value;
	}

	@Override
	protected float[] testFloatsRead(InputStream in) throws Exception {
		FloatArrayContainer container =  (FloatArrayContainer) unmarshaller.unmarshal(in);
		return container.values;
	}

	@Override
	protected void testDoubleWrite(double value, OutputStream out) throws Exception {
		DoubleContainer container = new DoubleContainer();
		container.value = value;
		marshaller.marshal(container, out);
	}

	@Override
	protected void testDoubleWrite(double[] value, OutputStream out) throws Exception {
		DoubleArrayContainer container = new DoubleArrayContainer();
		container.values = value;
		marshaller.marshal(container, out);
	}

	@Override
	protected double testDoubleRead(InputStream in) throws Exception {
		DoubleContainer container =  (DoubleContainer) unmarshaller.unmarshal(in);
		return container.value;
	}

	@Override
	protected double[] testDoublesRead(InputStream in) throws Exception {
		DoubleArrayContainer container =  (DoubleArrayContainer) unmarshaller.unmarshal(in);
		return container.values;
	}

	@Override
	protected void testStringWrite(String value, OutputStream out) throws Exception {
		StringContainer container = new StringContainer();
		container.value = value;
		marshaller.marshal(container, out);
	}

	@Override
	protected void testStringWrite(String[] value, OutputStream out) throws Exception {
		StringArrayContainer container = new StringArrayContainer();
		container.values = value;
		marshaller.marshal(container, out);
	}

	@Override
	protected String testStringRead(InputStream in) throws Exception {
		StringContainer container =  (StringContainer) unmarshaller.unmarshal(in);
		return container.value;
	}

	@Override
	protected String[] testStringsRead(InputStream in) throws Exception {
		StringArrayContainer container =  (StringArrayContainer) unmarshaller.unmarshal(in);
		return container.values;
	}

	@Override
	protected void testCompoundWrite(CompoundContainer container, OutputStream out)
			throws Exception {
		marshaller.marshal(container, out);
	}

	@Override
	protected void testCompoundWrite(CompoundContainer[] value, OutputStream out)
			throws Exception {
		CompoundArrayContainer container = new CompoundArrayContainer();
		container.values = value;
		marshaller.marshal(container, out);
	}

	@Override
	protected CompoundContainer testCompoundRead(InputStream in)
			throws Exception {
		return (CompoundContainer) unmarshaller.unmarshal(in);
	}

	@Override
	protected CompoundContainer[] testCompoundsRead(InputStream in)
			throws Exception {
		CompoundArrayContainer container =  (CompoundArrayContainer) unmarshaller.unmarshal(in);
		return container.values;
	}

}
